package com.activity.exg4pcd;

import com.google.zxing.integration.android.IntentIntegrator;
import com.ui.exg4pcd.R;

import domain.businessEntity.cardinfo.CardInfo;
import domain.businessService.cardinfo.CardService;
import domain.businessService.cardinfo.ICardService;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ExchangeActivity extends Activity {
	public ICardService service;
	public CardInfo tempcard=new CardInfo();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_exchange);
		service=new CardService();
		findViewById(R.id.btn_qrcode).setOnClickListener(qrcode);
		tempcard=service.getCardInfo(0);	
	}
	private final Button.OnClickListener qrcode = new Button.OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
		      Bundle bundle = new Bundle();
		      bundle.putString(ContactsContract.Intents.Insert.NAME,tempcard.getName());
		      bundle.putString(ContactsContract.Intents.Insert.PHONE, tempcard.getPhone());
		      bundle.putString(ContactsContract.Intents.Insert.EMAIL, tempcard.getEmail());
		      encodeBarcode("CONTACT_TYPE", bundle);
		}
		};
	  private void encodeBarcode(CharSequence type, Bundle data) {
		    IntentIntegrator integrator = new IntentIntegrator(this);
		    integrator.addExtra("ENCODE_DATA", data);
		    integrator.shareText(data.toString(), type); // data.toString() isn't used
		  }
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.exchange, menu);
		return true;
	}
	
	}

